package com.js.rtu.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.js.rtu.R;

import java.util.List;



public class DeviceAdapter extends BaseQuickAdapter<DeviceBean, BaseViewHolder> {

    private Context context;

    public DeviceAdapter(Context context, List<DeviceBean> data) {
        super(R.layout.item_device, data);
        this.context = context;

    }


    @Override
    protected void convert(BaseViewHolder helper, DeviceBean bean) {
        if (bean != null) {
            BluetoothDevice device=bean.getDevice();
            String name=device.getName()==null?"N/A":device.getName() ;
            helper.setText(R.id.txt_name,name );
            helper.setText(R.id.txt_address, device.getAddress());
            if (device.getBondState()== BluetoothDevice.BOND_BONDED) {
                helper.setText(R.id.txt_type, "已配对");
            }else {
                helper.setText(R.id.txt_type, "未配对");
            }
//            helper.setText(R.id.txt_type, "未配对");

            helper.setBackgroundRes(R.id.img_blue,
                   device.getType()==BluetoothDevice.DEVICE_TYPE_CLASSIC?
                           R.mipmap.ic_phone:R.mipmap.ic_blue_remote);
            helper.setText(R.id.tv_ssi, bean.getRssi()+" dBm");
            helper.addOnClickListener(R.id.tv_connect);
            if (bean.isConntect()) {
                helper.setVisible(R.id.tv_connect, true);
                helper.setText(R.id.tv_connect, "断开");
            }
            else {
                helper.setVisible(R.id.tv_connect, false);
                helper.setText(R.id.tv_connect, "连接");
            }

        }




    }




}
